home *** CD-ROM | disk | FTP | other *** search
/ Alles Voor Internet / Tout Pour Internet / alles voor internet.iso / MacInternet™ / Telnet / NCSA / tn3270 2.3d26 source / tn3270 / tcpevent.c < prev    next >
Text File  |  1991-05-29  |  7KB  |  277 lines

  1. /*
  2.  *  tn3270 for the Macintosh Source Code
  3.  *  Brown University Computing and Information Services
  4.  *  Version 2.3d21, January 17, 1991
  5.  *  Copyright (c) 1988, 1989, 1990, 1991 by Brown University and by
  6.  *  Peter John DiCamillo.
  7.  *
  8.  *  Permission is granted to any individual or institution to use, copy,
  9.  *  or redistribute the binary version of this software and its
  10.  *  documentation provided this notice and the copyright notices are
  11.  *  retained.  Permission is granted to any individual or non-profit
  12.  *  institution to use, copy, modify, or redistribute the source files
  13.  *  of this software provided this notice and the copyright notices are
  14.  *  retained.  This software may not be distributed for profit, either
  15.  *  in original form or in derivative works, nor can the source be
  16.  *  distributed to other than an individual or a non-profit institution.
  17.  *  Any  individual or group interested in seeing and/or using these
  18.  *  source files but who are prevented from doing so by the above
  19.  *  constraints should contact Don Wolfe, Assistant Vice-President for
  20.  *  Computer Systems at Brown University, (401) 863-7250, for possible
  21.  *  software licensing of the source developed at Brown.
  22.  *
  23.  *  Brown University and Peter John DiCamillo make no representations
  24.  *  about the suitability of this software for any purpose.
  25.  *
  26.  *  BROWN UNIVERSITY AND PETER JOHN DICAMILLO GIVE NO WARRANTY, EITHER
  27.  *  EXPRESS OR IMPLIED, FOR THE PROGRAM AND/OR DOCUMENTATION PROVIDED,
  28.  *  INCLUDING, WITHOUT LIMITATION, WARRANTY OF MERCHANTABILITY AND
  29.  *  WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE.
  30.  *
  31.  */
  32.  
  33. #define __SEG__ 3270tcp
  34. #include "maclib.h"
  35. #include "netevent.h"
  36. #include "hostform.h"
  37. #include "termdef.h"
  38. #include "globals.h"
  39.  
  40. extern char tcpinitok;        /* network code is active */
  41. extern int myport;
  42. extern char pend_conn;
  43. extern struct machinfo * mp;
  44. extern char vmxbgn;
  45. extern char vmxsub;
  46. extern unsigned char * rcvbuff;
  47. extern short rcvmax;
  48. extern char data_init;        /* flag for stream parsing */
  49. extern char serverconn;        /* flag for line mode server */
  50. extern char servermode;        /* server mode active */
  51. extern char hadascii;        /* flag for have had ascii data */
  52.  
  53. char tcpinv;                /* tcp pending invldscr */
  54. short rdportnum();
  55.  
  56. tcpevent()
  57. {
  58. int ev, what, data; 
  59. short cnt, i;
  60. char msg[128];
  61. struct machinfo *Slooknum();
  62. OSErr rc, createwindow();
  63.  
  64. myStask();
  65. ev = Sgetevent(USERCLASS | ERRCLASS | CONCLASS, &what, &data);
  66.  
  67. if (ev) {
  68.     sprintf(msg, "event = %d, class = %d, data = %d", ev, what, data);
  69.     putln(msg);
  70.  
  71.     switch(what) {
  72.         case CONCLASS:
  73.             switch(ev) {
  74.                 case CONOPEN:
  75.                             if (pend_conn == 2) {
  76.                                 pend_conn = 3;
  77.                                 online = 1;
  78.                                 rc = createwindow();
  79.                                 if (rc != noErr) {
  80.                                     tcplgout();
  81.                                     }
  82.                                 /*     if the session was opened by the api, we
  83.                                     delay registering the session until data
  84.                                     is received. (See telnet.c)  */
  85.                                 if (!apiopenpend) {
  86.                                     apiregister(1);
  87.                                     }
  88.                                 if (serverconn) {
  89.                                     servermode = 0;
  90.                                     srvswitch();
  91.                                     if (!logon) {
  92.                                         if (kblock) {
  93.                                             kblock = 0;
  94.                                             newstat();
  95.                                             }
  96.                                         hadascii = 1;
  97.                                         return;
  98.                                         }
  99.                                     }
  100.                                 }
  101.                             break;
  102.                 case CONDATA:
  103.                             if (data != myport) break;
  104.                             cnt = netread(data, rcvbuff+64, rcvmax);
  105.                             myStask();
  106.                             if (cnt == 0) break;
  107.                             if (cnt < 0) {
  108.                                 closeresponse(closeNetFail);
  109.                                 tcplgout();
  110.                                 break;
  111.                                 }
  112.                             if (logon) {
  113.                                 wr_active = 1;
  114.                                 newstat();
  115.                                 }
  116.                             while (cnt > 0) {
  117.                                 telrcv(rcvbuff+64, cnt);
  118.                                 myStask();
  119.                                 cnt = netread(data, rcvbuff+64, rcvmax);
  120.                                 myStask();
  121.                                 }
  122.                             if (wr_active && (!needwrite)) {
  123.                                 wr_active = 0;
  124.                                 newstat();
  125.                                 }
  126.                             if (tcpinv && (data_init == 1)) {    /* 3270 mode */
  127.                                 tcpinv = 0;
  128.                                 invldscr();
  129.                                 if (pndbeep) {
  130.                                     pndbeep = 0;
  131.                                     myStask();    /* beep takes a while */
  132.                                     beep();
  133.                                     myStask();
  134.                                     }
  135.                                 }
  136.                             else if (logon == 0) {            /* line mode */
  137.                                 if (pndbeep) {
  138.                                     pndbeep = 0;
  139.                                     myStask();    /* beep takes a while */
  140.                                     beep();
  141.                                     myStask();
  142.                                     }
  143.                                 }
  144.                             if (cnt < 0) {
  145.                                 closeresponse(closeNetFail);
  146.                                 tcplgout();
  147.                                 }
  148.                             break;
  149.                 case CONCLOSE:
  150.                             if (data != myport) break;
  151.                             closeresponse(closeNetClose);
  152.                             tcplgout();
  153.                             break;
  154.                 case CONFAIL:
  155.                             if (pend_conn == 2) {
  156.                                 stoperr(conalrt);
  157.                                 pend_conn = 0;
  158.                                 kblcode = 4;
  159.                                 if (apiopen) {
  160.                                     apiopenerr(openConnFailed);
  161.                                     }
  162.                                 }
  163.                             break;
  164.                 default:
  165.                             break;
  166.                 }
  167.             break;
  168.  
  169.         case USERCLASS:
  170.             switch(ev) {
  171.                 case DOMOK:
  172.                             if ((pend_conn == 1) && (data == myport)) {
  173.                                 mp = Slooknum(data);
  174.                                 if (mp == 0) {
  175.                                     putln("Slooknum failed!");
  176.                                     stoperr(topnalrt);
  177.                                     pend_conn = 0;
  178.                                     kblcode = 4;
  179.                                     if (apiopen) {
  180.                                         apiopenerr(openConnFailed);
  181.                                         }
  182.                                     break;
  183.                                     }
  184.                                 else {
  185.                                     sprintf(msg, "number for %s is %d.%d.%d.%d",
  186.                                     mp->hname, mp->hostip[0], mp->hostip[1],
  187.                                     mp->hostip[2], mp->hostip[3]);
  188.                                     putln(msg);
  189.                                     }
  190.                                 myport = Snetopen(mp, rdportnum());
  191.                                 if (myport < 0) {
  192.                                     putln("Snetopen failed!");
  193.                                     stoperr(topnalrt);
  194.                                     pend_conn = 0;
  195.                                     kblcode = 4;
  196.                                     if (apiopen) {
  197.                                         apiopenerr(openConnFailed);
  198.                                         }
  199.                                     }
  200.                                 else pend_conn = 2;
  201.                                 }
  202.                             break;
  203.                 case DOMFAIL:
  204.                             if ((pend_conn == 1) && (data == myport)) {    
  205.                                 stoperr(numalrt);
  206.                                 pend_conn = 0;
  207.                                 kblcode = 4;
  208.                                 if (apiopen) {
  209.                                     apiopenerr(openResFailed);
  210.                                     }
  211.                                 }
  212.                             break;
  213.                 case FTPCOPEN:
  214.                             ftpcopen = 1;
  215.                             if (myWindow != 0) newstat();
  216.                             putln("FTP control connection opened");
  217.                             break;
  218.                 case FTPCLOSE:
  219.                             ftpcopen = 0;
  220.                             if (myWindow != 0) newstat();
  221.                             putln("FTP control connection closed");
  222.                             break;
  223.                 case FTPBEGIN:
  224.                             ftpdopen = 1;
  225.                             if (myWindow != 0) newstat();
  226.                             putln("FTP data connection opened");
  227.                             break;
  228.                 case FTPEND:
  229.                             ftpdopen = ftplopen = 0;
  230.                             if (myWindow != 0) newstat();
  231.                             putln("FTP data or list connection closed");
  232.                             break;
  233.                 case FTPLIST:
  234.                             ftplopen = 1;
  235.                             if (myWindow != 0) newstat();
  236.                             putln("FTP list connection opened");
  237.                             break;
  238.                 case RCPBEGIN:
  239.                             putln("rcp transfer begin");
  240.                             break;
  241.                 case RCPEND:
  242.                             putln("rcp transfer ended");
  243.                             break;
  244.                 default:
  245.                             break;
  246.                 }
  247.             break;
  248.         case ERRCLASS:
  249.             NetError(data);
  250.             break;
  251.         default:
  252.             break;
  253.         }
  254.     myStask();
  255.     }
  256.  
  257. while ((kbqsize > 0) && (!kblock)) {
  258.     if (vmxbgn && (!vmxsub)) break;
  259.     hndkbd(kbqueue[0].code, kbqueue[0].shift);
  260.     kbqsize--;
  261.     myStask();
  262.     if (kbqsize > 0)
  263.         for (i=0; i < kbqsize; i++) {
  264.             kbqueue[i].code = kbqueue[i+1].code;
  265.             kbqueue[i].shift = kbqueue[i+1].shift;
  266.             }
  267.     }
  268. }
  269.  
  270. myStask()
  271. {
  272. if (tcpflg && tcpinitok) {
  273.     Stask();
  274.     /* if (ftpcopen || ftpdopen || ftplopen)
  275.         rftpd(CONOPEN+1);    shouldn't need this ? */
  276.     }
  277. }